package br.edu.eseg.brproject.model.action;

import br.edu.eseg.brproject.model.*;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityQuery;
import java.util.Arrays;

@Name("licaoList")
public class LicaoList extends EntityQuery<Licao> {

	private static final String EJBQL = "select licao from Licao licao join licao.projeto projeto join licao.areaimpactada areaimpactada join licao.impactolicao impactolicao join licao.prioridadelicao prioridadelicao";

	private static final String[] RESTRICTIONS = {
			"lower(licao.descricao) like lower(concat(#{licaoList.licao.descricao},'%'))",
			"lower(licao.titulo) like lower(concat(#{licaoList.licao.titulo},'%'))",
			"lower(licao.projeto.nome) like lower(concat(#{licaoList.licao.projeto.nome},'%'))",
			"licao.areaimpactada.id = #{licaoList.licao.areaimpactada.id}",
			"licao.impactolicao.id = #{licaoList.licao.impactolicao.id}",
			"licao.prioridadelicao.id = #{licaoList.licao.prioridadelicao.id}"};

	private Licao licoes = new Licao();

	public LicaoList() {
		setEjbql(EJBQL);
		setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
		setMaxResults(25);
		getLicao().setAreaimpactada(new Areaimpactada());
		getLicao().setProjeto(new Projeto());
		getLicao().setImpactolicao(new Impactolicao());
		getLicao().setPrioridadelicao(new Prioridadelicao());
		setRestrictionLogicOperator("and");
	}

	public Licao getLicao() {
		return licoes;
	}
}
